'''
（1）打开视频端口
（2）发送实时视频请求
（3）等待设备回复200OK
（4）发送ACK
（5）播放码流
（6）停止视频请求
（7）关闭视频端口
（8）普通等待
向摄像机发送Invite消息,消息头域中携带 Subject字段,表明点播的视频源ID、发送方媒体流序列号、ZLMediaKit接收流使用的IP、端口号、 接收端媒体流序列号等参数,SDP消息体中 s字段为“Play”代表实时点播，y字段描述SSRC值,f字段描述媒体参数。
'''

msg = '''
INVITE sip:34020000001320000001@192.168.0.101:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.102:5061;rport;branch=tNQkW1OXWSLF4Fbw
From: <sip:34020000002000000001@192.168.0.102>;tag=8018952467
To: <sip:34020000001320000001@192.168.0.101:5060>
Call-ID: 05572471
CSeq: 20 INVITE
Max-Forwards: 70
Contact: <sip:34020000002000000001@192.168.0.102:5061>
Content-Type: application/sdp
Subject: 34020000001320000001:0,34020000002000000001:0
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL, UPDATE ,PRACK,REFER,SUBSCRIBE,NOTIFY,MESSAGE
Content-Length: 191

v=0
o=34020000001110000001@3402000000.spvmn.cn 0 0 IN IP4 192.168.0.102
s=Play
c=IN IP4 192.168.0.102
t=0 0
m=video 10000 RTP/AVP 96 98 97
a=rtpmap:96 PS/90000
a=recvonly
y=05572471


'''
msg2 = '''
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.102:5060;rport=5060;branch=yugVzTgzUG79xiOf
From: <sip:34020000002000000001@192.168.0.102>;tag=2859287914
To: <sip:34020000001320000001@192.168.0.120:5060>;tag=7709968
Call-ID: 8780641828
CSeq: 20 INVITE
Contact: <sip:34020000001320000001@192.168.0.120:5060>
Content-Type: application/sdp
User-Agent: IP Camera
Content-Length:   187

v=0
o=34020000001320000001 3515 3515 IN IP4 192.168.0.120
s=Play
c=IN IP4 192.168.0.120
t=0 0
m=video 15060 RTP/AVP 96
a=sendonly
a=rtpmap:96 PS/90000
a=filesize:0
y=2147483647
    '''
from common.tools import Tool
from common.conf import conf
from msg.action import Action
import json,time

t = Tool()
c = conf
a = Action()
exp = 1800




# # send()
# cid = t.my_redis.get("34020000001320000001")
# if cid is not None:
#     print("cid,ssrc alredy exist=======", cid, t.cid2ssrc(cid))
#     invite = t.my_redis.get(cid)
#     print(len(invite))
# else:
#     Tool().my_redis.set("34020000001320000001", "play")
#     time.sleep(4)
#     cid = t.my_redis.get("34020000001320000001")
#     print("new cid,ssrc=======", cid, t.cid2ssrc(cid))
# 使用方法 8位数字, 作为invite cid ,同时也是ssrc.
sipid='34020000002000000001'
chan = "34020000001320000001" #cam
cid = "34020000001110000001" #nvr

a=(0xe0 & 0x7E) >> 1
print (11,a)
